package com.gewu.pm.ui.activity.funds;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.FreezerDetailBean;
import com.gewu.pm.bean.ManagementBean;
import com.gewu.pm.ui.activity.base.BaseManagementActivity;
import com.gewu.pm.ui.activity.filter.FilterFreezerManagementActivity;
import com.gewu.pm.ui.adapter.funds.FreezerAdapter;

/**
 * 冰柜管理
 */
public final class FreezerManagementActivity extends BaseManagementActivity<ManagementBean>
        implements FreezerAdapter.OnEditClickListener {

    public static void start(Context context) {
        Intent intent = new Intent(context, FreezerManagementActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected String getPageTitle() {
        return "冰柜管理";
    }

    @Override
    protected String getSearchHint() {
        return "输入冰柜名称/冰柜铭牌编码/终端编码";
    }

    @Override
    protected String getBottomButtonText() {
        return "新增冰柜";  // 显示底部按钮
    }

    @Override
    protected AppAdapter<ManagementBean> createAdapter() {
        FreezerAdapter adapter = new FreezerAdapter(getContext());
        adapter.setOnEditClickListener(this);  // 设置编辑按钮监听
        return adapter;
    }

    @Override
    protected void loadData() {
        mDataList.clear();
        mDataList.add(new ManagementBean("终端-1876a-1——冰柜1"));
        mDataList.add(new ManagementBean("终端-1876a-1——冰柜1"));

        // 保存原始数据用于搜索
        setOriginalData(mDataList);

        mAdapter.setData(mDataList);
        updateEmptyView();
    }

    @Override
    protected String getSearchText(ManagementBean item) {
        // 搜索冰柜名称（item 左上角的文字）
        return item.getName();
    }

    @Override
    protected void onBottomButtonClick() {
        // 跳转到新增冰柜页面
        FreezerEditActivity.startForAdd(this);
    }

    @Override
    public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
        ManagementBean item = mAdapter.getItem(position);
        // 跳转到冰柜详情（传递冰柜ID）
        FreezerDetailActivity.start(this, "1");//应该传id  暂时这么写
    }

    @Override
    public void onEditClick(int position, ManagementBean item) {
        // 跳转到编辑冰柜页面（需要传递完整数据）
        // TODO: 将 ManagementBean 转换为 FreezerDetailBean 或直接加载完整数据
        FreezerDetailBean freezerData = new FreezerDetailBean();
        freezerData.setId("1");//应该传id  暂时这么写
        freezerData.setFreezerName(item.getName());
        // TODO: 设置其他字段
        
        FreezerEditActivity.startForEdit(this, freezerData);
    }

    @Override
    public void onRightClick(View view) {
        super.onRightClick(view);
        FilterFreezerManagementActivity.start(getActivity());
    }
}
